/*
 * Copyright (c) 2001-2007, Inversoft, All Rights Reserved
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
 * either express or implied. See the License for the specific
 * language governing permissions and limitations under the License.
 */
package org.inversoft.vertigo.fck.action;

import java.io.File;

import org.inversoft.vertigo.fck.service.FCKService;
import org.inversoft.vertigo.fck.service.UploadResult;

import com.google.inject.Inject;
import com.opensymphony.xwork2.Action;

/**
 * <p>
 * This action handles uploads. However, it delegates the the
 * {@link org.inversoft.vertigo.fck.service.FCKService#upload(java.io.File, String, String, String)}
 * method for all of the work. Look at that methods Javadoc for all
 * of the configuration that is required or optional.
 * </p>
 *
 * @author  Brian Pontarelli
 */
public class Upload implements Action {
    // Service
    final FCKService fckService;
    
    // Input
    private String type;
    private File file;
    private String contentType;
    private String fileName;
    // Output
    private UploadResult result;

    @Inject
    public Upload(FCKService fckService) {
        this.fckService = fckService;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public File getNewFile() {
        return file;
    }

    public void setNewFile(File newFile) {
        this.file = newFile;
    }

    public String getNewFileContentType() {
        return contentType;
    }

    public void setNewFileContentType(String newFileContentType) {
        this.contentType = newFileContentType;
    }

    public String getNewFileFileName() {
        return fileName;
    }

    public void setNewFileFileName(String newFileFileName) {
        this.fileName = newFileFileName;
    }

    public UploadResult getResult() {
        return result;
    }

    @Override
    public String execute() {
        this.result = fckService.upload(file, fileName, contentType, type);
        if (this.result.isError()) {
            return ERROR;
        }

        return SUCCESS;
    }
}